package com.example.demo528.service;

import com.example.demo528.domain.Demo;
import com.example.demo528.domain.DemoExample;
import com.example.demo528.mapper.DemoMapper;
import com.example.demo528.req.DemoReq;
import com.example.demo528.resp.DemoResp;
import com.example.demo528.utils.CopyUtil;
import jakarta.annotation.Resource;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class DemoService {
    @Resource
    private DemoMapper demoMapper;

    public List<DemoResp> list(DemoReq req){
        DemoExample demoExample = new DemoExample();
        DemoExample.Criteria criteria = demoExample.createCriteria();
        criteria.andNameLike("%"+req.getName()+"%");

        List<Demo> demoList=demoMapper.selectByExample(demoExample);

//        List<DemoResp> respList=new ArrayList<>();
//        for (Demo demo:demoList) {
//            DemoResp demoResp=new DemoResp();
//            ebookResp.setName(ebook.getName());
//            BeanUtils.copyProperties(demo,demoResp);
//            DemoResp demoResp= CopyUtil.copy(demo, DemoResp.class);
//            respList.add(demoResp);
//        }
        List<DemoResp> respList=CopyUtil.copyList(demoList, DemoResp.class);
        return respList;
    }
}
